package cn.wanda.bi.sunshine.platform.server.controller.statistics;

import cn.wanda.bi.sunshine.platform.server.aspect.CheckLimit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.wanda.bi.sunshine.platform.server.aspect.AuthUser;
import cn.wanda.bi.sunshine.platform.server.aspect.Logging;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppArticleDetail;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppArticleInfo;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppArticleTitleTarget;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppDailyPicareaFlow;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppPrivilegeShoppingPage;
import cn.wanda.bi.sunshine.platform.server.bean.model.A06727AppPubSelectedHomepageStat;
import cn.wanda.bi.sunshine.platform.server.controller.request.DimUserLabelAllAuthAppidRequest;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.ListResponse;
import cn.wanda.bi.sunshine.platform.server.controller.response.common.SimpleResponse;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppArticleDetailService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppArticleInfoService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppArticleTitleTargetService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppDailyPicareaService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppPrivilegeShoppingPageService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppPubHomepageStatService;
import cn.wanda.bi.sunshine.platform.server.service.statistics.A06727AppPubSelectedHomepageStatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * Created by wangfupeng1
 */
@Api(description = "统计数据727")
@RestController
@RequestMapping(value = "/v1/statistics", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class StatisticsController implements Logging {

    public static final Logger logger = LoggerFactory.getLogger(StatisticsController.class);

    @Autowired
    private A06727AppPubHomepageStatService a06727AppPubHomepageStatService;

    @Autowired
    private A06727AppPubSelectedHomepageStatService selectedHomepageStatService;

	@AuthUser
    @ApiOperation("查询homepage表，根据时间进行分页查询传入参数startTime日期最小值，endTime日期最大值，index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间，返回数据 datekey : 日期,\n" +
            " happylife_pv :乐活页面曝光量（PV）," +
            " happylife_uv :乐活页面访问人数（UV）," +
            " happylife_selected_pv:乐活精选页面曝光量（PV）," +
            " happylife_selected_uv:乐活精选页面访问人数（UV）," +
            " happylife_promotion_pv:乐活优惠页面曝光量（PV）," +
            " happylife_promotion_uv:乐活优惠页面访问人数（UV）," +
            " happylife_shopping_pv:乐活逛街页面曝光量（PV）," +
            " happylife_shopping_uv:乐活逛街页面访问人数（UV）," +
            " op_time:时间戳," +
            " execution_id:批次号," )
    @RequestMapping(value = "/homepage", method = RequestMethod.GET)
	@CheckLimit
    ListResponse<DimUserLabelAllAuthAppidRequest> homepage(
            @ApiParam(value = "日期最小值") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "日期最大值") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", defaultValue = "1") Integer index,
            @ApiParam(value = "条数") @RequestParam(value = "limit", defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token
    ) {
        return a06727AppPubHomepageStatService.list(endTime, startTime, index, limit);
    }

    @Autowired
    private A06727AppArticleInfoService ArticleService;

    @AuthUser
    @ApiOperation("查询articleInfo表，查询文章信息，传入参数startTime日期最小值，endTime日期最大值，index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间，dt : 日期,\n" +
            "  title_sw_pv  : 常规文章标题总曝光量（PV）," +
            "  title_sw_uv  : 常规文章标题总访问人数（UV）," +
            "  title_pv  : 常规文章标题总点击量," +
            "  title_uv  : 常规文章标题总点击人数," +
            "  title_user_avg  : 常规文章标题总人均点击数," +
            "  title_click_rate  : 常规文章标题总点击率," +
            "  user_browse_duration  : 常规文章用户平均浏览时长（单位：秒）," +
            "  detail_sw_pv  : 常规文章详情页曝光量（PV）," +
            "  detail_sw_uv  : 常规文章详情页访问人数（UV）," +
            "  detail_pv  : 常规文章详情页标题点击量," +
            "  detail_uv  : 常规文章详情页标题点击人数," +
            "  detail_user_avg  : 常规文章详情页人均点击数," +
            "  detail_click_rate  : 常规文章详情页点击率," +
            "  detail_user_browse_duration  : 常规文章详情页页面浏览时长," +
            "  detail_user_sw_avg  : 平均每位用户浏览常规文章数," +
            "  op_time : 操作时间戳," +
            "  execution_id : 执行批次号")
    @RequestMapping(value = "/article", method = RequestMethod.GET)
    @CheckLimit
    ListResponse<A06727AppArticleInfo> article(
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return ArticleService.article(startTime, endTime, index, limit);
    }

    @Autowired
    private A06727AppArticleTitleTargetService a06727AppArticleTitleTargetService;

    @CheckLimit
	@AuthUser
    @ApiOperation("查询文章标题，传入参数startTime日期最小值，endTime日期最大值，index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间，返回数据 ：date_key : 发布日期,\n" +
            "  article_sum : 文章总数,\n" +
            "  article_category : 文章分类,\n" +
            "  title_click_person : 标题点击人数,\n" +
            "  title_exposure_sum : 标题曝光人数,\n" +
            "  article_click_frequency : 文章点击频率,\n" +
            "  title_click_num : 标题点击次数,\n" +
            "  detail_pv : 详情页pv,\n" +
            "  detail_uv : 详情页uv,\n" +
            "  dtail_visit_time : 详情页平均访问时长,\n" +
            "  article_comment_sum : 文章总评论数,\n" +
            "  article_assist_sum : 文章点赞总数,\n" +
            "  article_share_sum : 文章总分享数,\n" +
            "  article_collect_sum : 文章总收藏数")
    @RequestMapping(value = "/articleTitleTarget", method = RequestMethod.GET)
    ListResponse<A06727AppArticleTitleTarget> articleTitleTarget(
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return a06727AppArticleTitleTargetService.articleTitleTarget(startTime, endTime, index, limit);
    }

    @Autowired
    private A06727AppArticleDetailService a06727AppArticleDetailService;

    @CheckLimit
	@AuthUser
    @ApiOperation("查询articleDetail，传入参数startTime日期最小值，endTime日期最大值，appoint约定值,articleNo文章编号,articleTitle文章标题,articleSource文章来源,articleEditor责任编辑人,index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间，返回数据article_no  : 文章编号,\n" +
            "  article_title  : 文章标题,\n" +
            "  article_publish_date : 发布日期,\n" +
            "  article_type  : 文章类型,\n" +
            "  article_type_label  : 文章分类标签,\n" +
            "  article_title_click_total  : 标题点击次数,\n" +
            "  article_title_vistor_total  : 标题点击人数,\n" +
            "  article_title_access_total  : 标题曝光次数,\n" +
            "  article_click_per ,\n" +
            "  article_pv  : 详情页PV,\n" +
            "  article_uv  : 详情页UV,\n" +
            "  article_detail_access_time  : 详情页平均访问时长,\n" +
            "  article_comment_total  : 文章总评论数,\n" +
            "  article_upvote_total  : 文章总点赞数,\n" +
            "  article_share_total  : 文章总分享数,\n" +
            "  article_store_total  : 文章总收藏数,\n" +
            "  article_source  : 文章来源,\n" +
            "  article_editor  : 责任编辑人,")
    @RequestMapping(value = "/articleDetail", method = RequestMethod.GET)
    ListResponse<A06727AppArticleDetail> articleDetail( @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
                                                        @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "约定字符") @RequestParam(value = "appoint", required = false,defaultValue = "") String appoint,
            @ApiParam(value = "文章编号") @RequestParam(value = "articleNo", required = false) String articleNo,
            @ApiParam(value = "文章标题") @RequestParam(value = "articleTitle", required = false) String articleTitle,
            @ApiParam(value = "文章来源") @RequestParam(value = "articleSource", required = false) String articleSource,
            @ApiParam(value = "文章编辑") @RequestParam(value = "articleEditor", required = false) String articleEditor,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return a06727AppArticleDetailService.articleDetail(appoint,startTime,endTime,articleNo, articleTitle, articleSource, articleEditor, index, limit);
    }

    @CheckLimit
	@AuthUser
    @ApiOperation("查询所有选择的主页统计数据，传入参数startTime日期最小值，endTime日期最大值，index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间,返回数据datekey :日期,\n" +
            "  happylife_pv : 乐活页面曝光量（PV）,\n" +
            "  happylife_uv : 乐活页面访问人数（UV）,\n" +
            "  happylife_selected_pv : 乐活精选页面曝光量（PV）,\n" +
            "  happylife_selected_uv : 乐活精选页面访问人数（UV）,\n" +
            "  happylife_promotion_pv : 乐活优惠页面曝光量（PV）,\n" +
            "  happylife_promotion_uv : 乐活优惠页面访问人数（UV）,\n" +
            "  happylife_shopping_pv : 乐活逛街页面曝光量（PV）,\n" +
            "  happylife_shopping_uv : 乐活逛街页面访问人数（UV）,\n" +
            "  op_time :时间戳,\n" +
            "  execution_id : 批次号,")
    @RequestMapping(value = "/homepageStat", method = RequestMethod.GET)
    ListResponse<A06727AppPubSelectedHomepageStat> selectedHomepage(
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return selectedHomepageStatService.list(startTime, endTime, index, limit);
    }

    @Autowired
    private A06727AppDailyPicareaService a06727AppDailyPicareaService;

    @CheckLimit
	@AuthUser
    @ApiOperation("查询每天的PicareaFlow，传入参数startTime日期最小值，endTime日期最大值，index分页页码，limit每页条数，token用户认证信息，userName用户万信，loginTime登录时间，返回数据datekey :日期,\n" +
            "  title_all_pv  : 每日图说标题总曝光量PV,\n" +
            "  title_all_uv  : 每日图说标题总访问人数UV,\n" +
            "  title_click_pc  : 每日图说标题总点击量,\n" +
            "  title_click_uv  : 每日图说标题总点击人数,\n" +
            "  title_click_avg  :每日图说标题总人均点击数,\n" +
            "  title_click_rate  :每日图说标题总点击率,\n" +
            "  relpage_pv  : 每日图说总PV,\n" +
            "  relpage_uv  : 每日图说总UV,\n" +
            "  relpage_time_avg  :每日图说相关页面用户平均浏览时长,\n" +
            "  browse_page_avg_cnt  : 平均每位用户浏览每日图说页面量,\n" +
            "  detailpage_all_pv  : 每日图说详情页曝光量PV,\n" +
            "  detailpage_all_uv  : 每日图说详情页访问人数UV,\n" +
            "  detailpage_browse_avg_time  :每日图说详情页用户平均浏览时长,\n" +
            "  read_avg_cnt  :用户平均阅读每日图说文章数量,\n" +
            "  list_pv  : 每日图说列表页曝光量PV,\n" +
            "  list_uv  : 每日图说列表页访问人数UV,\n" +
            "  list_title_pv  : 每日图说列表页标题点击量,\n" +
            "  list_title_uv  : 每日图说列表页标题点击人数,\n" +
            "  list_title_click_avg  :每日图说列表页标题人均点击数,\n" +
            "  list_title_click_rate  :每日图说列表页点标题击率,\n" +
            "  list_browse_avg_time  :每日图说列表页用户平均浏览时长,\n" +
            "  op_time :时间戳,\n" +
            "  execution_id big : 批次号,")
    @RequestMapping(value = "/dailyPicareaFlow", method = RequestMethod.GET)
    ListResponse<A06727AppDailyPicareaFlow> dailyPicareaFlow(
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return a06727AppDailyPicareaService.dailyPicareaFlow(startTime, endTime, index, limit);
    }

    @Autowired
    private A06727AppPrivilegeShoppingPageService a06727AppPrivilegeShoppingPageService;

    @CheckLimit
	@AuthUser
    @ApiOperation("查询shoppingPage, 输入参数：开始时间（startTime），结束时间（endTime），页码（index），每页条数（limit），token用户认证信息，userName用户万信，loginTime登录时间； " +
            "输出数据：A06727AppPrivilegeShoppingPage对象((日期)dateKey, (乐活优惠页面-闪购商品曝光量（PV）)flashsaleSwPv, (乐活优惠页面-闪购商品访问人数（UV）)flashsaleSwUv, (乐活优惠页面-闪购商品点击量)flashsalePv, (乐活优惠页面-闪购商品点击人数)flashsaleUv, (乐活优惠页面-闪购商品人均点击数)flashsalePerTimes, (活优惠页面-闪购商品点击率)flashsalePerRate, (乐活优惠页面-优惠券栏位曝光量（PV）)couponlistSwPv, (乐活优惠页面-优惠券栏位访问人数（UV）)couponlistSwUv, (乐活优惠页面-优惠券栏位点击量)couponlistPv, (乐活优惠页面优惠券栏位点击人数)couponlistUv, (乐活优惠页面-优惠券栏位人均点击数)couponlistPerTimes, (乐活优惠页面-优惠券栏位点击率)couponlistPerRate, (乐活逛街页面-广场列表栏位曝光量（PV）)plazaareaSwPv, (乐活逛街页面-广场列表栏位访问人数（UV）)plazaareaSwUv, (乐活逛街页面-广场列表栏位点击量)plazaareaPv, (乐活逛街页面-广场列表栏位点击人数)plazaareaUv, (乐活逛街页面-广场列表栏位人均点击数)plazaareaPerTimes, (乐活逛街页面-广场列表栏位点击率)plazaareaPerRate, (操作时间)opTime, (版本号)executionId)")
    @RequestMapping(value = "/shoppingPage", method = RequestMethod.GET)
    ListResponse<A06727AppPrivilegeShoppingPage> shoppingPage(
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "页码") @RequestParam(value = "index", required = false, defaultValue = "1") Integer index,
            @ApiParam(value = "每页条数") @RequestParam(value = "limit", required = false, defaultValue = "20") Integer limit,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return a06727AppPrivilegeShoppingPageService.shoppingPage(startTime, endTime, index, limit);
    }

    @AuthUser
    @ApiOperation("查询文章类型点击次数，传入参数articleTypeLabel文章分类标签, startTime开始时间, endTime结束时间，token用户认证信息，userName用户万信，loginTime登录时间, 输出数据是一个点击次数的平均值")
    @RequestMapping(value = "/articleClickPer", method = RequestMethod.GET)
    SimpleResponse articleClickPer(
            @ApiParam(value = "文章分类标签") @RequestParam(value = "articleTypeLabel") String articleTypeLabel,
            @ApiParam(value = "开始时间") @RequestParam(value = "startTime", required = false) Long startTime,
            @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false) Long endTime,
            @ApiParam(value = "登录校验码") @RequestHeader(value = "token") String token

    ) {
        return a06727AppArticleDetailService.articleClickPer(articleTypeLabel,startTime, endTime);
    }
}
